<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <!-- 允许缩放 -->
    <meta name="viewport" id="view" content="width=device-width,initial-scale=1.0,maximum-scale=1; minimum-scale=1, user-scalable=yes" />
    <!-- 禁止缩放 -->
    <!-- <meta name="viewport" id="view" content="width=device-width,initial-scale=1.0,user-scalable=0" /> -->
    <!-- <meta name="viewport" id="view" content="width=device-width,initial-scale=1.0"> -->
    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />
    <link rel="icon" href="<%= BASE_URL %>logo.svg">
    <link href="<%= BASE_URL %>img/icons/newMailNoti.png"> <!-- 新邮件提醒图标给后端一个路径 --->
    <title> </title>
  </head>
  <!-- 修复ios active无法监听问题 -->
  <body ontouchstart="">
    <script type="text/javascript"
            src="http://at.alicdn.com/t/font_2489321_jc5khosrcu.js"></script>
    <noscript>
      <strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
    </noscript>
    <div id="app"></div>
    <!-- built files will be auto injected -->

    <script>
      const isIOSDevice = !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //判断是否是 iOS终端 
      if (isIOSDevice) {
        /**
         * Created by chen on 17/10/28.
         */
        /**
         * Vue Bridge Webview v1.0
         * https://github.com/cmp-cc/vue-bridge-webview
         *
         * Copyright 2016, cmp-cc
         * Released under the MIT license
         */
  
        (function () {
          /**
           *  vue-bridge-webview config
           *
           * @type {{bridgeWebViewDelay: number}}
           */
          console.warn("IOS设备 调用桥方法文件 使用右滑接管方法 ")
  
          var bridgeConfig = {
            bridgeWebViewDelay: 0.2 * 1000,
            callHandle: {}, // bridge android / ios
            silent: false
          }
          var bridgeStatusIsOk = false
          var $bridge = {
            registerHandler: function (name, callback) {
              if (bridgeConfig.silent) {
                console.log(name, ' register handler failure')
              }
            },
            callHandler: function (name, params, callback) {
              if (bridgeConfig.silent) {
                console.log(name, ' call handler webView failure')
              }
            }
          }
  
          // ============ device init operation start ===========
  
          /* setup WebView Javascript Bridge for ios , ios 初始化 */
          function setupWebViewJavascriptBridge (callback) {
            // 初始化status
            bridgeStatusIsOk = false
            if (window.WebViewJavascriptBridge) {
              return callback(WebViewJavascriptBridge)
            }
            if (window.WVJBCallbacks) {
              return window.WVJBCallbacks.push(callback)
            }
            window.WVJBCallbacks = [callback]
            var WVJBIframe = document.createElement('iframe')
            WVJBIframe.style.display = 'none'
            WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'
            document.documentElement.appendChild(WVJBIframe)
            setTimeout(function () { document.documentElement.removeChild(WVJBIframe) }, 0)
          }
  
          /* 用于创建桥接对象的函数 , android 初始化 */
          function connectWebViewJavascriptBridge (callback) {
            // 如果桥接对象已存在，则直接调用callback函数
            if (window.WebViewJavascriptBridge) {
              callback(WebViewJavascriptBridge)
            }
            // 否则添加一个监听器来执行callback函数
            else {
              document.addEventListener('WebViewJavascriptBridgeReady', function () {
                callback(WebViewJavascriptBridge)
              }, false)
            }
          }
  
          /* device detect for ios/android */
          if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
            setupWebViewJavascriptBridge(function (bridge) {
              $bridge = bridge
            })
          } else if (/(Android)/i.test(navigator.userAgent)) {
            connectWebViewJavascriptBridge(function (bridge) {
              $bridge = bridge
            })
          }
  
          // ==============device init operation end ============
  
          var VueBridgeWebView = {
            install: function (Vue) {
              Vue.prototype.$bridge = this
              Vue.bridge = this
  
              // config
              bridgeConfig.slient = Vue.config.slient
            },
  
            /**
             *  Android / IOS 调用JS,需要明确调用的`function名称` .
             *
             *
             * @param name `function name`
             * @param registerCallback 回调的响应事件
             */
            registerHandler: function (name, registerCallback) {
              if ($bridge['registerHandler']) {
                setTimeout(function () {
                  $bridge.registerHandler(name, registerCallback)
                }, bridgeConfig.bridgeWebViewDelay)
              } else {
                console.log("don't built-in WebView invoking ", name, '{registerHandler}')
              }
            },
  
            /**
             *  JS 调用 Android / IOS
             *
             *  name: 回调名称, android/ios 名称 ,eg: 'getUserInfo'
             *  params 请求参数, eg: { 'userId' : 1}
             *  callback: response(响应函数)
             *
             *  eg: this.$bridge.callHandler('getUserInfo',{'userId':1},function(data){...})
             *
             */
            callHandler: function (name, params, callback) {
              console.log('lib-bridge')
              if ($bridge['callHandler']) {
                /* 解决部分系统加载延迟导致 ios/android 不响应问题 */
                if (bridgeStatusIsOk) {
                  $bridge.callHandler(name, params, function (data) {
                    if (typeof callback === 'function') {
                      callback(data)
                    }
                  })
                } else {
                  var isFirstCallHandlerSuccess = false
                  var count = 0
                  var WebiewJavascriptTimer = setInterval(function () {
                    if (!isFirstCallHandlerSuccess) {
                      if (count > 25) {
                        clearInterval(WebiewJavascriptTimer)
                        return false
                      }
                      $bridge.callHandler(name, params, function (data) {
                        if (typeof callback === 'function') {
                          clearInterval(WebiewJavascriptTimer)
                          isFirstCallHandlerSuccess = true
                          bridgeStatusIsOk = true
                          callback(data)
                        }
                      })
                    }
                    count++
                  }, bridgeConfig.bridgeWebViewDelay)
                }
              } else {
                console.log("don't built-in WebView invoking ", name, '{callHandler}')
              }
            }
          }
  
          if (typeof exports === 'object') {
            module.exports = VueBridgeWebView
          } else if (typeof define === 'function' && define.amd) {
            define([], function () { return VueBridgeWebView })
          } else if (window.Vue) {
            window.$bridge = VueBridgeWebView
            Vue.use(VueBridgeWebView)
          } else {
            window.$bridge = VueBridgeWebView
          }
          if (window.$bridge) {
            var u = navigator.userAgent
            var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
            if (isIOS) {
              window.$bridge.callHandler('opp_get_userinfo', {}, function () {})   
            }
          }
        })()
      }
    </script>
  </body>
</html>
